<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="uiTags" prefix="ui"%>

<ui:body>
	<div  class="easyui-layout" data-options="fit:true" style="margin-top: 5px;">
		<div data-options="region:'west',split:false,border:false"
			style="width: 20%;height: 100%">
			<ui:datagrid id="functionmanage_first_level" pagination="false"
				title="一级菜单">
				<ui:dgtoolbar>
					<ui:button onclick="functionMange.functionAdd('1')" value="新增" icon="icon-add" />
					<ui:button onclick="functionMange.functionEdit('1')" value="编辑" icon="icon-mini-edit" />
					<ui:button onclick="functionMange.functionDel('1')" value="删除" icon="icon-remove" />
				</ui:dgtoolbar>
				<ui:columntext text="functionid" filed="functionid" hidden="true"/>
				<ui:columntext text="功能名称" filed="name" width="1"/>
				<ui:columntext text="顺序" filed="sx"  width="1"/>
			</ui:datagrid>
		</div>

		<div data-options="region:'center',split:false,border:false"
			style="width: 50%;height: 100%">
			<ui:datagrid id="functionmanage_second_level" pagination="false"
				title="二级菜单">
				<ui:dgtoolbar>
					<ui:button onclick="functionMange.functionAdd('2')" value="新增" icon="icon-add" />
					<ui:button onclick="functionMange.functionEdit('2')" value="编辑" icon="icon-mini-edit" />
					<ui:button onclick="functionMange.functionDel('2')" value="删除" icon="icon-remove" />
				</ui:dgtoolbar>
				<ui:columntext text="functionid" filed="functionid" hidden="true"/>
				<ui:columntext text="功能名称" filed="name" />
				<ui:columntext text="URL" filed="url"  />
				<ui:columntext text="顺序" filed="sx"  />
			</ui:datagrid>
		</div>

		<div data-options="region:'east',split:false,border:false"
			style="width: 30%;height: 100%">
			<ui:datagrid id="functionmanage_button_level" pagination="false"
				title="按钮">
				<ui:dgtoolbar>
					<ui:button onclick="functionMange.functionAdd('3')" value="新增" icon="icon-add" />
					<ui:button onclick="functionMange.functionEdit('3')" value="编辑" icon="icon-mini-edit" />
					<ui:button onclick="functionMange.functionDel('3')" value="删除" icon="icon-remove" />
				</ui:dgtoolbar>
				<ui:columntext text="functionid" filed="functionid" hidden="true"/>
				<ui:columntext text="功能名称" filed="name" width="1"/>
				<ui:columntext text="备注" filed="bz" width="3"/>
			</ui:datagrid>
		</div>
</ui:body>
<script type="text/javascript">
var functionMange = {
		queryChildrenFuncs:function(datagridId,parentId){
			var param = new Object();
			param.parentid= parentId;
			asyRefreshDatagrid(datagridId,"function/getChilderenFuns",param);
		},
		functionAdd:function(type){
			var callback;
			var row;
			var parentId;
			var datagridid;
			if(type=='1'){
				parentId = '${rootId}';
				datagridid = "functionmanage_first_level";
			}else if(type =='2'){
				row = getSelectedRow("functionmanage_first_level")
				if(row){
					parentId = row.functionid;
					datagridid = "functionmanage_second_level";
				}else{
					showWarnAlert("请先选中一级父菜单后操作！");
					return;
				}
			}else if(type=='3'){
				row = getSelectedRow("functionmanage_second_level")
				if(row){
					parentId = row.functionid;
					datagridid = "functionmanage_button_level";
				}else{
					showWarnAlert("请先选中二级父菜单后操作！");
					return;
				}
			}
			callback = "functionMange.queryChildrenFuncs('"+datagridid+"','"+parentId+"');functionMange.refreshCascadeGrid('"+type+"');";
			createResponse("新增",800,500,"function/enterFunctionAdd?type=" + type+"&parentId=" +parentId,callback);
		},
		functionDel:function(type){
			var row,functionid,parentrow,parentId,datagridid;
			if(type == '1'){
				parentId = '${rootId}';
				datagridid = "functionmanage_first_level";
			}
			if(type == '2'){
				parentrow = getSelectedRow("functionmanage_first_level");
				datagridid = "functionmanage_second_level";
			}
			if(type == '3'){
				parentrow = getSelectedRow("functionmanage_second_level");
				datagridid = "functionmanage_button_level";
			}
			row = getSelectedRow(datagridid);
			if(row){
				functionid = row.functionid;
			}else{
				showWarnAlert("请先选中后操作！");
				return;
			}
			if(parentrow!=null){
				parentId = parentrow.functionid;
			}
			var param = new Object();
			param.functionid = functionid;
			ajaxRequest("function/deleteFunc",param);
			showWarnAlert("删除成功！");
			functionMange.queryChildrenFuncs(datagridid,parentId);
			refreshCascadeGrid(type);
		},
		functionEdit:function(type){
			var row,functionid,parentrow,parentId,datagridid,callback;
			if(type == '1'){
				parentId = '${rootId}';
				datagridid = "functionmanage_first_level";
			}
			if(type == '2'){
				parentrow = getSelectedRow("functionmanage_first_level");
				datagridid = "functionmanage_second_level";
			}
			if(type == '3'){
				parentrow = getSelectedRow("functionmanage_second_level");
				datagridid = "functionmanage_button_level";
			}
			row = getSelectedRow(datagridid);
			if(row){
				functionid = row.functionid;
			}else{
				showWarnAlert("请先选中后操作！");
				return;
			}
			if(parentrow!=null){
				parentId = parentrow.functionid;
			}
			callback = "functionMange.queryChildrenFuncs('"+datagridid+"','"+parentId+"');functionMange.refreshCascadeGrid('"+type+"');";
			createResponse("修改",800,500,"function/enterFunctionEdit?type=" + type+"&functionid=" +functionid,callback);
		},
		refreshCascadeGrid:function(type){
			if(type == '1'){
				functionMange.queryChildrenFuncs('functionmanage_second_level',null);
				functionMange.queryChildrenFuncs('functionmanage_button_level',null);
			}else if(type == '2'){
				functionMange.queryChildrenFuncs('functionmanage_button_level',null);
			}
		}
}
	functionMange.queryChildrenFuncs('functionmanage_first_level','${rootId}');
	getObject("functionmanage_first_level").datagrid({
		onSelect:function(rowIndex, rowData){
			functionMange.queryChildrenFuncs('functionmanage_second_level',rowData.functionid);
			functionMange.queryChildrenFuncs('functionmanage_button_level',null);
		}
	});
	getObject("functionmanage_second_level").datagrid({
		onSelect:function(rowIndex, rowData){
			functionMange.queryChildrenFuncs('functionmanage_button_level',rowData.functionid);
		}
	});
</script>